<?php
namespace dingtalk;

use dingtalk\util\Http;

class User
{
    /**
     * 获取成员详情
     * @param $accessToken
     * @param $userid
     * @return string
     */
    public static function getUserInfo($accessToken, $userid)
    {
        $response = Http::get("/user/get", ["access_token" => $accessToken, "userid" => $userid]);
        return obj2array($response);
    }

    /**
     * 创建成员
     * @param $accessToken
     * @param $user
     * @return bool
     */
    public static function createUser($accessToken, $user)
    {
        $response = Http::post("/user/get", ["access_token" => $accessToken],json_encode($user));
        return obj2array($response);
    }
    /**
     * 更新成员
     * @param $accessToken
     * @param $user
     * @return bool
     */
    public static function User($accessToken, $user)
    {
        $response = Http::post("/user/update", ["access_token" => $accessToken],json_encode($user));
        return obj2array($response);
    }
    /**
     * 删除成员
     * @param $accessToken
     * @param $userid
     * @return bool
     */
    public static function deleteUser($accessToken, $userid)
    {
        $response = Http::get("/user/delete", ["access_token" => $accessToken,"userid"=>$userid]);
        return obj2array($response);
    }
    /**
     * 批量删除成员
     * @param $accessToken
     * @param $userid
     * @return bool
     */
    public static function batchdeleteUser($accessToken, $useridlist)
    {
        $response = Http::post("/user/batchdelete", ["access_token" => $accessToken], json_encode($useridlist));
        return obj2array($response);
    }

    /**
     * 获取部门成员列表简单
     * @param $accessToken
     * @param $deptId
     * @return mixed
     */
    public static function simplelist($accessToken,$deptId){
        $response = Http::get("/user/simplelist", ["access_token" => $accessToken,"department_id"=>$deptId]);
        return obj2array($response);
    }

    /**
     * 获取部门成员列表详情
     * @param $accessToken
     * @param $deptId
     * @return mixed
     */
    public static function getlist($accessToken,$deptId){
        $response = Http::get("/user/list", ["access_token" => $accessToken,"department_id"=>$deptId]);
        return obj2array($response);
    }

    /**
     * 获取管理员列表
     * @param $accessToken
     * @return mixed
     */
    public static function getAdmin($accessToken){
        $response = Http::get("/user/get_admin", ["access_token" => $accessToken]);
        return obj2array($response);
    }

    /**
     * 获取会员ID通过Unionid
     * @param $accessToken
     * @param $deptId
     * @return mixed
     */
    public static function getUseridUnionid($accessToken,$unionid){
        $response = Http::get("/user/getUseridByUnionid", ["access_token" => $accessToken,"unionid"=>$unionid]);
        return obj2array($response);
    }
}